from blls.label_blls.label_bll import LabelBLL
from handlers.base_handler import BaseHandler
from utils.check_params_utlil import CheckParams
from utils.handler_util import HandlerUtil


class LabelListByProject(BaseHandler):
    def post(self):
        check = CheckParams(params=self.request_data,
                            conditions=[["project_id", True, ""],
                                        ]).check()
        if not check.is_success:
            return self.write(HandlerUtil.set_failure_response(message=check.message))
        res = LabelBLL(request=self).get_label_by_project(check.data)
        return self.write(HandlerUtil.set_response(data=res.data, message=res.message, is_success=res.is_success))

class AddLabel(BaseHandler):
    def post(self):
        check = CheckParams(params=self.request_data,
                            conditions=[["project_id",True,""],
                                        ["name",True,""],
                                        ["color",False,""]
                                        ]).check()
        if not check.is_success:
            return self.write(HandlerUtil.set_failure_response(message=check.message))
        res = LabelBLL(request=self).add_label(check.data)
        return self.write(HandlerUtil.set_response(data=res.data, message=res.message, is_success=res.is_success))

# class DeleteLabel(BaseHandler):
#     def post(self):
#         check = CheckParams(params=self.request_data,
#                             conditions=[["label_id",True,""],
#                                         ]).check()
#         if not check.is_success:
#             return self.write(HandlerUtil.set_failure_response(message=check.message))
#         res = LabelBLL(request=self).delete_label(check.data)
#         return self.write(HandlerUtil.set_response(data=res.data, message=res.message, is_success=res.is_success))